---
title: "Optimal Taxation of Robots - Code Documentation"
author: Uwe Thuemmel
date: "2022-07-17"
titlepage: true
...

# Introduction

This document describes the code for the paper *Optimal Taxation of Robots*. 

# Required software

The code for the paper is written in *R* and *MATLAB*. Moreover, third party solvers are used to solve non-linear optimization problems (Knitro) as well as optimal control problems (GPOPS-II). These solvers need to be purchased separately, though trial versions exist (though these trial versions might have restrictions that make them unsuitable for solving the respective problems required for this paper).

The software used is listed below (with the respective versions)

- R (version 4.0.2)
- MATLAB (version 2019b)
- [Artelys Knitro](https://www.artelys.com/solvers/knitro/) (version 12.1.1)
- [GPOPS-II](http://www.gpops2.com/) (version 2.4)
- [LyX](https://www.lyx.org/) (version 2.3.3)

The document processor LyX is used to automatically generate the tables for the paper in TeX format. The R files depend on a number of external packages. For the respective versions see `./tables/R_packages.pdf`.

# Makefile

There is a makefile in the root directory which organizes the files and dependencies required to generate all figures and tables for the paper. To generate all results, simply run

```console
make all
```

in the terminal. Please note that the robustness computations may take about 10 days to complete.

To generate the entire set of results anew, first clean up by running

```console
make clean
```

Then, run `make all`.

It is also possible to only run some parts of the code. Below, I describe the separate steps which go into generating the results for the paper and also include the respective `make` commands by which these steps can be run. Note that `make` notices if in the sequence of steps there are changes in results or in code upstream on which steps downstream depend. In that case, the outdated downstream steps are run such that everything is up to date. Read more about `make` and makefiles [here](https://de.wikipedia.org/wiki/Make). I refer to the files which are generated by a specific `make` command as *targets* and to the files on which a specific step depends as *dependencies*.

## Directories
In the steps below, I use placeholders from the makefile to refer to different directories. In the makefile, one refers to placeholders as \$(NAME). I keep this convention here. The placeholders for the directories are

|Placeholder|Value|
|---|---|
|dir_project|.|
|dir_matlab|\$(dir_project)/src/matlab|
|dir_densities|\$(dir_matlab)/Densities|
|dir_r|\$(dir_project)/src/r|
|dir_calibration|\$(dir_matlab)/Calibration|
|dir_data_raw|\$(dir_project)/data/raw|
|dir_data_generated|\$(dir_project)/data/generated|
|dir_simulation|\$(dir_data_generated)/matlab/simulation|
|dir_optimtax|\$(dir_data_generated)/matlab/OptimTax|
|dir_optimtax_gpops|\$(dir_optimtax)/gpops|
|dir_optimtax_hsv|\$(dir_optimtax)/hsv|
|dir_compensation_hsv|\$(dir_optimtax)/compensation_hsv|
|dir_compensation_gpops|\$(dir_optimtax)/compensation_gpops|
|dir_calibration_output|\$(dir_data_generated)/matlab/Calibration|
|dir_figures|\$(dir_project)/figures|
|dir_doc_tables|\$(dir_project)/tables|

# Separate steps

The table below lists the separate steps that are executed in order when calling `make all`. Click on *Detail* for a more detailed description of the respective step.

|Step|Make command|Details|
|----|------------|-------|
|Prepare CPS data|`make prepare_cps`|[Details](#prepare-cps-data)|
|Compute summary statistics|`make sumstats`|[Details](#compute-summary-statistics)|
|Prepare skill-distribution calibration|`make prepare_skill_dist_calibration`|[Details](#prepare-skill-distribution-calibration)|
|Calibrate skill-distribution|`make calibrate_skill_dist`|[Details](#calibrate-skill-distribution)|
|Post-process skill-distr. calibration|`make calibrate_skill_dist_post`|[Details](#post-process-skill-distribution-calibration)|
|Calibrate production function|`make calibrate_prod_fun`|[Details](#calibrate-production-function)|
|Calibrate inequity aversion|`make calibrate_inequity_aversion`|[Details](#calibrate-inequity-aversion)|
|Generate tables|`make tables`|[Details](#generate-tables)|
|Simulate economy under status-quo tax system|`make simulate_given_tax`|[Details](#simulate-economy-under-status-quo-tax-system)|
|Compute optimal taxes in full model|`make optimtax_gpops`|[Details](#compute-optimal-taxes-in-full-model)|
|Compute tau used in compensation|`make optimtax_hsv_adjust_tau_hsv`|[Details](#compute-tau-used-in-welfare-compensation)|
|Compute welfare compensation|`make compensate_gpops`|[Details](#compute-welfare-compensation)|
|Analyze sensitivity| `make analyze_sensitivity`|[Details](#analyze-sensitivity)|
|Generate plots|`make plots`|[Details](#generate-plots)|

## Prepare CPS data
Prepares the sample from the raw CPS data.

Runs `$(dir_r)/prepare_cps.R` and generates 

|File|Description|
|---|---|
|\$(dir_data_generated)/r/morg_data_stacked_90.csv|Sample, where wagesample==1 corresponds to participants|

### Dependencies
|File|Description|
|---|---|
|\$(dir_r)/cps_functions.R|Functions to process CPS data|
|\$(dir_data_raw)/daviddorn/occ1970_occ1990dd.dta|Occupation-classification conversion| 
|\$(dir_data_raw)/daviddorn/occ1980_occ1990dd.dta|Occupation-classification conversion|
|\$(dir_data_raw)/daviddorn/occ1990_occ1990dd.dta|Occupation-classification conversion|
|\$(dir_data_raw)/daviddorn/occ2000_occ1990dd.dta|Occupation-classification conversion|
|\$(dir_data_generated)/crosswalks/occ2012_occ1990.csv|Crosswalk for occupations|
|\$(dir_data_generated)/crosswalks/occ00_occ1990.csv|Crosswalk for occupations|
|\$(dir_data_raw)/AcemogluAutor2011/census-prep-files/occ1990dd-recode.csv|Occupation recoding based on Acemoglu & Autor (2011)| |\$(dir_data_raw)/fred/DPCERG3A086NBEA.csv|Consumer-price index|
|\$(dir_data_raw)/morg/morg90.dta|CPS data for 1990|

*Note*: Not all conversion files are actually used, but they would be used for samples from other years. The code allows for this.
The main file is also always part of the dependencies but not listed explicitly. In this case, `$(dir_r)/prepare_cps.R`.

## Compute summary statistics
Computes summary statistics based on the prepared sample.

Runs `$(dir_r)/sumstats.R` and generates

|File|Description|
|---|---|
|\$(dir_data_generated)/r/morg_sumstats_table.csv|Summary statistics by occupation and schooling|
|\$(dir_data_generated)/r/morg_sumstats_all_table.csv|Summary statistics by schooling|
|\$(dir_data_generated)/r/part_share.csv|Mass of participants by occupation and overall|
|\$(dir_data_generated)/r/mean_inc.csv|Avg. annual labor income in 1990 in 2016 USD|

### Dependencies
|File|Description|
|---|---|
|\$(dir_data_generated)/r/morg_data_stacked_90.csv|Sample, where wagesample==1 corresponds to participants|

## Prepare skill-distribution calibration

Runs `$(dir_r)/prepare_skill_distribution_targets.R` to generate the targets used when calibrating the skill-distribution. The target files are

|File|Description|
|---|---|
|\$(dir_data_generated)/r/freq_pareto_10_M.csv|mass per wage bin for M| 
|\$(dir_data_generated)/r/freq_pareto_10_R.csv|mass per wage bin for R| 
|\$(dir_data_generated)/r/freq_pareto_10_C.csv|mass per wage bin for C|  
|\$(dir_data_generated)/r/wagebins_pareto_10_M.csv|wage bins corresponding to deciles for M| 
|\$(dir_data_generated)/r/wagebins_pareto_10_R.csv|wage bins corresponding to deciles for R|
|\$(dir_data_generated)/r/wagebins_pareto_10_C.csv|wage bins corresponding to deciles for C| 

### Dependencies
|File|Description|
|---|---|
|\$(sumstats_targets)|Output from skill-distribution calibration|

## Calibrate skill-distribution
Calibrates skill-distribution (and participation cost distribution.

Runs `$(dir_matlab)/Calibration/calibrate_abilityFixed.m` and generates

|File|Description|
|---|---|
|\$(dir_data_generated)/matlab/Calibration/\$(calibration_version)_abilityDistThreeFixC_sol.csv|Solution (parameters) of calibration|
|\$(dir_data_generated)/matlab/Calibration/\$(calibration_version)_abilityDistThreeFixC_mom.csv|Derived moments at calibration|  |\$(dir_data_generated)/matlab/Calibration/\$(calibration_version)_results.mat|Calibration results, including calibration object|


The file `results.mat` is used in the post analysis for which it is useful to directly load the calibration object.

### Dependencies

|File|Description|	
|---|---|
|$(dir_matlab)/Densities/abilityDistFixed.m|Skill-distribution object|
|\$(dir_matlab)/Densities/ParticipationNormal.m|Participation-cost-distribution object|
|\$(dir_matlab)/Densities/SkillAndParticipation.m|Object combining skill- and participation-cost-distribution|	
|\$(dir_matlab)/Densities/plognpdf.m|Pareto log-normal PDF|	
|\$(dir_matlab)/Densities/plogncdf.m|Parteo log-normal CDF|	
|\$(dir_matlab)/Densities/std_norminv.m|Inverse standard normal distribution|	
|\$(dir_matlab)/UtilityFunctions/UtilityQuasiLinear.m|Quasi-linear utility function|	
|\$(dir_matlab)/Calibration/CalibrateKrusellWithRobotsEconomy.m|Object which implements the economy to be calibrated| 	
|\$(dir_matlab)/Calibration/CalibrateKrusellWithRobotsEconomyKnitro_con.opt|Option file for Knitro|	
|\$(prepare_skill_dist_calibration_targets)|[see above](#prepare-skill-distribution-calibration)|	
|\$(dir_data_raw)/AcemogluRestrepo2018/dec_eps_AR2018.csv|Elasticity targets from Acemoglu & Restrepo (2018)|	
|\$(dir_data_generated)/r/part_share.csv|Mass of participants [(see above)](#compute-summary-statistics)|
|\$(dir_data_generated)/r/mean_inc.csv|Avg. annual labor income in 1990 in 2016 USD|
|\$(dir_data_raw)/constants.csv|Constants used throughout|
|\$(tools)|Tools for file handling and numerical integration. [(see here)](#tools)|	

*Note*: Acemoglu & Restrepo (2018) is the working paper version of Acemoglu & Restrepo (2019).

## Post-process skill-distribution calibration
Post-processes the outcomes from the skill-distribution calibration.

Runs `$(dir_matlab)/Calibration/calibrate_skill_dist_post.m` and generates

|File|Description|	
|---|---|
|\$(dir_data_generated)/matlab/Calibration/$(calibration_version)_conditional_densities.csv|Wage densities conditional on participation and employment shares|
|\$(dir_data_generated)/matlab/Calibration/$(calibration_version)_deciles_eps.csv|Elasticities of wage distribution deciles wrt. robots|

The output files are later used for plotting Figures 1 and 2 in the paper.

### Dependencies

|File|Description|	
|---|---|
|\$(calibrate_skill_dist_targets)|[see above](#calibrate-skill-distribution)|

## Calibrate production function
Calibrates the production function.

Runs `$(dir_matlab)/Calibration/calibrate_production_function.m` to generate

|File|Description|	
|---|---|
|\$(dir_data_generated)/matlab/Calibration/$(calibration_version)_KrusellRobotsEach_sol.csv|Calibrated production function parameters| |\$(dir_data_generated)/matlab/Calibration/$(calibration_version)_KrusellRobotsEach_mom.csv|Derived moments|

### Dependencies

|File|Description|	
|---|---|
|\$(calibrate_skill_dist_targets)|[see above](#calibrate-skill-distribution)|
|\$(dir_matlab)/Calibration/CalibrateKrusellWithRobotsEachEconomy.m|Object that implements economy for production function calibration|
|\$(densities)|Collection of densities [(see here)](#densities)|
|\$(dir_matlab)/Economies/KrusellWithRobotsEachEconomy.m|Object that implements the model economy|
|\$(dir_matlab)/ProductionFunctions/KrusellRobotsEach.m|Object that implements the production function| 
|\$(dir_matlab)/UtilityFunctions/UtilityQuasiLinear.m|Object that implements the utility function|
|\$(dir_data_raw)/constants.csv|Constants used throughout|
|\$(dir_matlab)/Calibration/production_function_calibration.opt|Knitro options file|
|\$(tools)|Tools for file handling and numerical integration. [(see here)](#tools)|

## Calibrate inequity aversion
Calibrates the government's inequity aversion such that the status-quo tax system is close-to-optimal. This is done by solving for the optimal tau and lambda (and the transfer) of the CRP tax system in the calibrated model economy for different values of inequity aversion. Then, that value of inequity aversion is chosen for which the optimal tau and lambda are closest (sum of squared distances) to the status-quo values from Heathcote et al. (2017).

Runs `$(dir_matlab)/OptimTax/calibrate_inequity_aversion.m` to generate

|File|Description|	
|---|---|
|\$(dir_data_generated)/matlab/Calibration/inequ_par.csv|Degree of inequity aversion (iota in the paper, r in the code)|

### Dependencies

|File|Description|	
|---|---|
|\$(calibrate_prod_fun_targets)|Production-function-calibration targets [(see here)](#calibrate-production-function)|
|\$(calibrate_skill_dist_targets)|Skill-distribution-calibration targets [(see here)](#calibrate-skill-distribution)|
|\$(dir_data_raw)/constants.csv|Constants used throughout|
|\$(densities)|Collection of densities [(see here)](#densities)|
|\$(dir_matlab)/UtilityFunctions/UtilityQuasiLinear.m|Utility function object|
|\$(dir_matlab)/ProductionFunctions/KrusellRobotsEach.m|Production function object|
|\$(dir_matlab)/Economies/KrusellWithRobotsEachEconomy.m|Economy object|
|$(dir_matlab)/Economies/OptimTaxKnitro.opt|Knitro options file|

## Generate tables
Generates `.tex` files for all tables used in the paper. The tables are generated by LyX which calls R scripts to pull the required parameters from the generated data files. The main file is `$(dir_doc_tables)/master_tables.lyx` which embeds all lyx files for the tables.

### Dependencies
The dependencies include the lyx files, the R scripts as well as the generated data.

|File|Description|	
|---|---|
|\$(dir_doc_tables)/tab_cal_moments_combined.lyx|LyX file for Table 1|
|\$(dir_doc_tables)/tab_occ_classification.lyx|LyX file for Table 2|
|\$(dir_doc_tables)/tab_morg_sumstats.lyx|LyX file for Table 3|
|\$(dir_doc_tables)/tab_cal_ability_FixC.lyx|LyX file for Table 5|
|\$(dir_doc_tables)/tab_cal_prod_fun.lyx |LyX file for Table 6|
|\$(dir_doc_tables)/tab_cal_moments.R|R script for Table 1|
|\$(dir_doc_tables)/tab_morg_sumstats.R|R script for Table 3|
|\$(dir_doc_tables)/tab_cal_ability_FixC.R|R script for Table 5|
|\$(dir_doc_tables)/tab_cal_prod_fun.R |R script for Table 6|
|\$(dir_data_generated)/matlab/Calibration/$(calibration_version)_abilityDistThreeFixC_mom.csv|Moments from skill-distribution calibration|
|\$(calibrate_inequity_aversion_targets)|Inequity aversion|
|$(dir_data_generated)/matlab/Calibration/$(calibration_version)_KrusellRobotsEach_sol.csv|Production function parameters|
|\$(dir_doc_tables)/funcs_and_cons.R|Functions and constants used by scripts|  
|\$(sumstats_targets)|Summary statistics|
|\$(dir_data_raw)/constants.csv|Constants used throughout|
|\$(dir_data_generated)/r/part_share.csv|Participation rates|
|\$(dir_data_generated)/r/mean_inc.csv|Participation rates|
|calibration_version.txt|Name of calibration version| 

## Simulate economy under status-quo tax system
Simulates the economy for the status-quo tax system as well as for a tax system with a 10-fold higher robot tax for different levels of the robot price.

Runs `$(dir_matlab)/Calibration/equilibrium_price_change.m` to generate

|File|Description|	
|---|---|
|\$(dir_simulation)/$(calibration_version)_simulation.csv|Economy at different robot prices|
|\$(dir_simulation)/$(calibration_version)_simulation_high_tax.csv|Economy at different robot prices, high robot tax|

*Note*: The command also produces files of percentiles. These are only there for sanity checks and are not used further.

### Dependencies

|File|Description|	
|---|---|
|\$(densities|Collection of densities [(see here)](#densities)| 
|\$(calibrate_skill_dist_targets)|Targets from skill-distribution calibration [(see here)](#calibrate-skill-distribution)|
|\$(calibrate_prod_fun_targets)|Targets from production-function calibration [(see here)](#calibrate-production-function)|
|\$(dir_matlab)/Economies/KrusellWithRobotsEachEconomy.m|Economy object|
|\$(dir_matlab)/Economies/ComputeEquilibriumKnitro.opt|Knitro options file|
|\$(dir_matlab)/ProductionFunctions/KrusellRobotsEach.m|Production function object
|$(dir_matlab)/UtilityFunctions/UtilityQuasiLinear.m|Utility function object|
|\$(tools)|Collection of tools [(see here)](#tools)|

## Compute optimal taxes in full model
Computes the optimal tax system - including optimal taxes on capital, labor income, and the transfer - for different robot prices. Also computes two versions of a constrained optimal tax system with:

1. capital taxes as in the status-quo
2. equal tax on equipment and robots

These two versions are used when computing the welfare compensations. The make command `make optimtax_gpops` runs three sub-commands that correspond to the full optimum (`make optimtax_gpops_optimum`), the constrained optimum (1) (`make optimtax_gpops_default_capital_taxes`), and the constrained optimum (2) (`make optimtax_gpops_equipment_equal_robot_tax`). For all three recipes, the main file for computing optimal taxes is `$(dir_matlab)/GPOPS/GPOPSMain.m`. The three recipes have different targets but share most of the same dependencies. I first discuss `make optimtax_gpops_optimum`. The targets are

### Targets - optimum

|File|Description|	
|---|---|
|\$(dir_optimtax_gpops)/optimum_vars.csv|Optimal solution, single variables at each robot price (e.g. taxes on capital)|
|\$(dir_optimtax_gpops)/optimum_vectors.csv|Optimal solution, vectors at each robot price (e.g. taxes on income)|

### Dependencies - optimum
Below, I list the dependencies for `make optimtax_gpops_optimum`.

|File|Description|	
|---|---|
|\$(dir_matlab)/GPOPS/GPOPSFunctions.m|Object which collects the core functions that specify the optimal-control problem| 
|\$(dir_matlab)/GPOPS/GPOPSContinuous.m|Continuous functions, required by GPOPS|
|\$(dir_matlab)/GPOPS/GPOPSEndpoint.m|Endpoint functions, required by GPOPS|
|\$(dir_matlab)/GPOPS/ProductionFunction.m|Production function object|
|\$(dir_matlab)/GPOPS/SkillDistribution.m|Skill-distribution object| 
|\$(dir_matlab)/GPOPS/UtilityFunction.m|Utility function object|
|\$(dir_matlab)/GPOPS/compute_elasticities.m|Functions for computing elasticities wrt. a change in the number of robots|
|\$(dir_matlab)/GPOPS/ParticipationCostDistribution.m|Participation-cost distribution object|
|\$(dir_matlab)/GPOPS/GPOPS_plot_results.m|Computes summary statistics based on solution|
|\$(dir_matlab)/GPOPS/fit_plognpdf.m|Fits log-Normal distribution, used for normalization of skill-distribution to speed up computation|
|\$(dir_matlab)/Economies/KrusellWithRobotsEachEconomy.m|Economy object|
|\$(dir_matlab)/ProductionFunctions/KrusellRobotsEach.m|Production function object (why again?)|
|\$(dir_matlab)/UtilityFunctions/UtilityQuasiLinear.m|Utility function object (why again?)|
|\$(dir_matlab)/GPOPS/keepfield.m|Tool for keeping fields of struct (should move to tools)|
|\$(calibrate_skill_dist_targets)|Outcomes of skill-distribution calibration|
|\$(calibrate_prod_fun_targets)|Outcomes of production-function calibration|
|\$(calibrate_inequity_aversion_targets)|Outcome of inequity-aversion calibration|
|\$(tools)|Collection of tools [(see here)](#tools)|

### Targets - default capital taxes

|File|Description|	
|---|---|
|\$(dir_optimtax_gpops)/default_capital_tax_vars.csv|Constrained optimal solution, single variables at each robot price (e.g. taxes on capital)|
|\$(dir_optimtax_gpops)/default_capital_tax_vectors.csv|Constrained optimal solution, vectors at each robot price (e.g. taxes on income)|

### Dependencies - default capital taxes

All dependencies from the [optimum version](#dependencies-optimum) as well as the [targets](#targets-optimum) from the optimum version.

### Targets - equal tax on equipment and robots

|File|Description|	
|---|---|
|\$(dir_optimtax_gpops)/equipment_equal_robot_tax_vars.csv|Constrained optimal solution, single variables at each robot price (e.g. taxes on capital)|
|\$(dir_optimtax_gpops)/equipment_equal_robot_tax_vectors.csv|Constrained optimal solution, vectors at each robot price (e.g. taxes on income)|

### Dependencies - equal tax on equipment and robots

All dependencies from the [optimum version](#dependencies-optimum) as well as the [targets](#targets-optimum) from the optimum version.

## Compute tau used in welfare compensation

This step computes the optimal CRP tax system, given capital taxes, at the initial robot price. The result is then used when computing the welfare compensations for the various tax reforms. In these [welfare compensations](#compute-welfare-compensation), tax progressivity (tau) is kept fixed at the value computed in this step, while lambda and the transfer are adjusted to clear the budget constraint. I compute the optimal rate of tax progressivity since the value of tau from Heathcote et al. (2017) is only close-to-optimal. (I calibrate the inequity-aversion parameter such that the values for tau and lambda from Heathcote et al. (2017) are close-to-optimal. Under the functional-form constraint, the CRP status-quo tax system is thus only close-to-optimal. I do not want this slight suboptimality to count towards the welfare effects of the tax reform and therefore compute the optimal CRP tax system, which by construction features parameters very close to those in Heathcote et al. (2017). Note that in the code the parameters are called tau_hsv and lambda_hsv.

The main file is `$(dir_matlab)/OptimTax/optimtax_hsv.m`. It generates

|File|Description|	
|---|---|
|\$(dir_optimtax_hsv)/$(calibration_version)_adjust_tau_hsv.csv|Optimum with CRP tax system|

### Dependencies

|File|Description|	
|---|---|
|\$(densities)|Collection of densities [(see here)](#densities)|
|\$(calibrate_skill_dist_targets)|Output from skill-distribution calibration|
|\$(calibrate_prod_fun_targets)|Output from production-function calibration|
|\$(dir_matlab)/Economies/KrusellWithRobotsEachEconomy.m|Economy object|
|\$(dir_matlab)/ProductionFunctions/KrusellRobotsEach.m|Production function object|
|\$(dir_matlab)/UtilityFunctions/UtilityQuasiLinear.m|Utility function object|
|\$(calibrate_inequity_aversion_targets)|Output from inequity-aversion calibration|
|\$(optimtax_gpops_optimum_targets)|Solution for full optimum|
|\$(dir_matlab)/Economies/OptimTaxKnitro.opt|Knitro options file|
|$(tools)|Collection of tools [(see here)](#tools)|
    
## Compute welfare compensation
In this step, I compute the compensating variation of various tax reforms. I ask: how much extra resources in the CRP tax system (with fixed tau but flexible lambda and flexible transfer) would the government need to achieve the same level of welfare as after the following three reforms:

- Reform 1: Set non-linear income taxes as well as the transfer optimally, while keeping taxes on capital at their status-quo level.
- Reform 2: In addition to Reform 1, allow taxes on capital to be set optimally, under the restriction that taxes on robots and equipment must be equal.
- Reform 3: On top of Reform 2, allow for different taxes on robots and equipment.

In addition, I compute a fourth reform which only optimizes the robot tax, while keeping the rest of the tax system at its status-quo (apart from adjusting parameters `lambda` and `b` to clear the budget constraint).

The main file is `$(dir_matlab)/OptimTax/optimtax_hsv.m`.

### Dependencies
The dependencies include the dependencies and the target from [above](#compute-tau-used-in-welfare-compensation). In addition, the targets from the optimal tax computation with GPOPS (see [here](#compute-optimal-taxes-in-full-model) are needed, since these contain the welfare values of the three reforms. That, is the dependencies for

- `make compensate_gpops_default_capital_tax` include `$(optimtax_gpops_default_capital_tax_targets)`
- `make compensate_gpops_equipment_equal_robot_tax` include `$(optimtax_gpops_equipment_equal_robot_tax_targets)`
- `make compensate_gpops_optimum` include `$(optimtax_gpops_optimum_targets)`

The resources required to reach a certain welfare level are computed as the minimum resources needed such that the economy satisfies the constraint that a certain welfare level is reached.

The fourth reform is run by
- `make optimtax_hsv_adjust_tau_B`

its compensation, which depends on the output of the above recipe, is computed by
- `make compensate_optimal_robot_tax_hsv`

## Analyze sensitivity
This step studies the sensitivity of the calibrated production function parameters. It does so by varying one parameter at a time and computing the impact on the various moments.

## Sensitivity kappa gamma
Analyzes the sensitivity with respect to chosen parameters.


## Compute tax simple formula
Computes the optimal robot tax based on the simple model.


## Generate plots
This step generates all the plots for the paper. I break the section down into the various separate plots and their dependencies:

### Plots for calibration - Targets
The command is `make plots_skill_distribution` which runs `$(dir_r)/plot_density_vs_data_FixC.R` to produce

|File|Description|	
|---|---|
|\$(dir_figures)/calibration/plot_densities_combined.pdf|Figure 1|
|\$(dir_figures)/calibration/deciles_eps.pdf|Figure 2|

### Plots for calibration - Dependencies
|File|Description|	
|---|---|
|$(dir_r)/figures.R|Collection of plotting functions|
|\$(dir_data_generated)/r/morg_data_stacked_90.csv|Data sample|
|\$(calibrate_skill_dist_post_targets)|Processed calibration output|

### Plots for simulation given taxes - Targets
The command is `make plots_simulate_given_tax` which runs `$(dir_r)/produce_figures_simulate_given_tax.R` to produce

|File|Description|	
|---|---|
|\$(dir_figures)/simulation/low_high_tax_legend.pdf|Legend low/high tax|
|\$(dir_figures)/simulation/plots_simulate_given_tax_combined_top.pdf|Figure 3, top row|  
|\$(dir_figures)/simulation/legend_three_mrc.pdf|Legend occupation|
|\$(dir_figures)/simulation/plots_simulate_given_tax_combined_bottom.pdf|Figure 3, bottom row|

### Plots for simulation given taxes - Dependencies
|File|Description|	
|---|---|
|\$(dir_r)/figures.R|Collection of plotting functions|
|\$(simulate_given_tax_targets)|Simulation output|

### Plots for optimal taxes - Targets
These plots are based on the optimal taxes computed with GPOPS. They are produced by running `make plots_gpops` and run the main file `$(dir_r)/produce_figures_gpops.R`. The targets are

|File|Description|	
|---|---|
|\$(dir_figures)/GPOPS/gpops_plots_combined.pdf|Figure 4|
|\$(dir_figures)/GPOPS/legend_tax_compare.pdf|Figure 5, legend|
|\$(dir_figures)/GPOPS/gpops_tax_compare_combined.pdf|Figure 5| 

### Plots for optimal taxes - Dependencies

|File|Description|	
|---|---|
|\$(dir_r)/figures.R|Collection of plotting functions|
|\$(optimtax_gpops_optimum_targets)|Output from optimal tax computations [(see here)](#compute-optimal-taxes-in-full-model)|

### Plots for welfare compensation - Targets
Can be run as `make plots_compensation`. The main file is `$(dir_r)/produce_figures_compensation.R` which produces

|File|Description|	
|---|---|
|\$(dir_figures)/compensation/compensation_combined.pdf|Figure 6|
|\$(dir_figures)/compensation/compensation_tau_B.pdf|Figure 7|

### Plots for welfare compensation - Dependencies

|File|Description|	
|---|---|
|\$(dir_r)/figures.R|Collection of plotting functions|
|\$(dir_compensation_gpops)/\$(calibration_version)_compensation_baseline_default_capital_tax.csv|Compensation of reform 1| |\$(dir_compensation_gpops)/\$(calibration_version)_compensation_baseline_equipment_equal_robot_tax.csv|Compensation of reform 2|
|\$(dir_compensation_gpops)/\$(calibration_version)_compensation_baseline_optimum.csv|Compensation of reform 3|


### Plots for gains and losses

See `Makefile`

### Plots for formula decomposition - Targets
To generate the plots for the decomposition of the optimal tax formula run `make plots_formula_terms`. The main file is `$(dir_r)/produce_figures_formula_terms.R` which produces

|File|Description|	
|---|---|
|\$(dir_figures)/decomposition/formula_terms_combined.pdf|Figure 10|
|\$(dir_figures)/decomposition/tax_rev_combined.pdf|Figure 11|

### Plots for formula decomposition - Dependencies
|File|Description|	
|---|---|
|\$(dir_r)/figures.R|Collection of plotting functions| 
|\$(dir_optimtax_gpops)/optimum_vars.csv|Optimal tax results|

# File collections
## Tools
```console
tools = $(dir_matlab)/+tools/ChangeOfVariables.m $(dir_matlab)/+tools/csv2struct.m $(dir_matlab)/+tools/struct2csv.m $(dir_matlab)/+tools/Integration.m $(dir_matlab)/+tools/translators.m
```
## Densities
```console
densities = $(dir_densities)/ParticipationNormal.m  $(dir_densities)/SkillAndParticipation.m $(dir_densities)/abilityDistFixed.m $(dir_densities)/plogncdf.m $(dir_densities)/plognpdf.m $(dir_densities)/std_norminv.m
```
